package com.wn.class30.cotroller.houtai;

import com.wn.class30.entity.Cupon;
import com.wn.class30.entity.MealPay;
import com.wn.class30.service.MealPayService;
import com.wn.class30.tools.Page;
import com.wn.class30.tools.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 套餐消费记录
 * @author yuyu
 * @since 2020/4/19 23:04
 */
@RestController
@Slf4j
@RequestMapping("/houtai/page/finance/mealpay/")
public class MealPayController {

    @Resource
    private MealPayService mealPayService;

    @RequestMapping("list")
    @RequiresPermissions("/houtai/page/finance/mealpay/list")
    @ApiOperation(value = "查询优惠券")
    public Result selectMealPays(long page, Integer limit, String usertel, String mealId, String mealMoney,String startDate,String endDate) throws Exception {
        Map<String,String> map = new HashMap<>();
        map.put("page",String.valueOf((page-1)*limit));
        map.put("limit",String.valueOf(limit));
        map.put("usertel",usertel);
        map.put("mealId",mealId);
        map.put("mealMoney",mealMoney);
        map.put("startDate",startDate);
        map.put("endDate",endDate);
        List<MealPay> mealPayList = mealPayService.selectMealPays(map);
        long dataCount = mealPayService.count(map);
        Page page1 = new Page();
        int pageCount = (int)(dataCount%limit==0?dataCount/limit:dataCount/limit+1);
        page1.setTotalSize(dataCount);
        page1.setPageSize(limit);
        page1.setCurrentPage(page);
        page1.setTotalPage(pageCount);
        return new Result("0","success",page1,mealPayList);
    }
}
